Implement metadata_delete_after_commit_enabled and metadata_previous_versions_max for Iceberg table.
          #20863
        
          
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Description
Implement
metadata_delete_after_commit_enabledandmetadata_previous_versions_maxfor Iceberg table.Without this feature, old metadata files (XXX.metadata.json files) will remains on the file system indefinitely after commit.
This corresponds to
write.metadata.delete-after-commit.enabledandwrite.metadata.previous-versions-maxproperties (see: https://iceberg.apache.org/docs/latest/maintenance/#remove-old-metadata-files)The following has been implemented:
This PR depends on #20410 which implemented
$metadata_log_entriessystem table for Iceberg table. This system table provides visibility on metadata file. Some testing codes are using$metadata_log_entries.First 2 commits are from #20410. Only the last commit is for this PR.
Fix #19582
Fix #14128
Supersede #20011
Implementation of
metadata_previous_versions_maxmetadata_previous_versions_maxis implemented by Iceberg's TableMetadata which Trino is using for commit. Trino only needs to set Iceberg table'swrite.metadata.previous-versions-maxproperty for this to work.Below is the call stack of an INSERT into Iceberg table.
Implementation of
metadata_delete_after_commit_enabledTrino is doing TableOperations by itself. The required logic has been added to
*TableOperations.Reference implementation in Iceberg:
https://github.com/apache/iceberg/blob/6a3b2d7c153412b01c746debb018c544516f2bbd/core/src/main/java/org/apache/iceberg/BaseMetastoreTableOperations.java#L412-L440
Release notes
(x) Release notes are required, with the following suggested text: